package com.zengqingfa.springboot.redis.rest;

import com.zengqingfa.springboot.redis.client.JedisClientCluster;
import com.zengqingfa.springboot.redis.config.RedisConfig;
import com.zengqingfa.springboot.redis.config.RedisProperties;
import com.zengqingfa.springboot.redis.dto.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @fileName: RedisController
 * @author: zengqf3
 * @date: 2020-12-30 19:48
 * @description:
 */
@RestController
@RequestMapping("/redis")
@Slf4j
public class RedisController {
    @Autowired
    private RedisProperties redisProperties;

    @Autowired
    private RedisConfig redisConfig;

    @Autowired
    private JedisClientCluster jedisClientCluster;

    @GetMapping(value = "/getRedisValue")
    public String getRedisValue() {
        log.info("redisProperties:{}", redisProperties.toString());
        log.info("Nodes:{}", redisConfig.getJedisCluster().getClusterNodes());
        log.info("redisProperties:{}", redisProperties.toString());
        log.info("redisProperties:{}", redisProperties.toString());
        System.out.println(jedisClientCluster.get("12"));
        return jedisClientCluster.get("12");
    }

    @GetMapping(value = "/getValue")
    public String getValue(@RequestParam("key") String key) {
        log.info("key:{},value={}", key, jedisClientCluster.get(key));
        String value = jedisClientCluster.get(key);
        return value;
    }


    @PostMapping(value = "/setValue")
    public String setValue(@RequestBody UserInfo info) {
        log.info("key:{},value={}", info.getKey(), info.getValue());
        String s = jedisClientCluster.get(info.getKey());
        System.out.println("s=" + s);
        String set = jedisClientCluster.set(info.getKey(), info.getValue());
        return set;
    }
}
